package com.studyweb.mapper;

import com.studyweb.pojo.entity.PaperQuestion;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PaperQuestionMapper {
    
    /**
     * 插入试卷题目关联
     */
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(PaperQuestion paperQuestion);
    
    /**
     * 根据试卷ID查询所有关联的题目
     */
    @Select("SELECT * FROM paper_question WHERE paper_id = #{paperId} ORDER BY question_order")
    List<PaperQuestion> selectByPaperId(Long paperId);
    
    /**
     * 根据试卷ID删除所有关联的题目
     */
    @Delete("DELETE FROM paper_question WHERE paper_id = #{paperId}")
    void deleteByPaperId(Long paperId);
    
    /**
     * 根据试卷ID和题目ID删除指定的题目关联
     */
    @Delete("DELETE FROM paper_question WHERE paper_id = #{paperId} AND question_id = #{questionId}")
    void deleteByPaperIdAndQuestionId(@Param("paperId") Long paperId, @Param("questionId") Long questionId);
    
    /**
     * 根据ID删除试卷题目关联
     */
    @Delete("DELETE FROM paper_question WHERE id = #{id}")
    void deleteById(Long id);
}